package da.metricscraft.client.frames.layers;

import java.awt.Graphics;
import java.awt.Point;
import java.awt.image.BufferedImage;
import java.util.HashMap;

import da.metricscraft.client.frames.GraphicsPanel;

public abstract class Layer<T> {
	
	protected BufferedImage layerImage;
	protected String layerName;
	protected Graphics graphics;
	protected Point canvasPosition = new Point(0,0);
	protected Point size;
	protected T data;
	protected boolean isActive;
	protected boolean activatedOnce = false;
	protected Layer(String name, Graphics g, Point size){
		layerName = name;
		graphics = g;
		this.size = size;
		isActive = false;
		update(false);
	}
	public abstract void update(boolean newdraw);
	public void unload(){
		layerImage = new BufferedImage(1,1,0);
	}
	public void draw(){
		if (layerImage != null){
			
			if (isActive){
				graphics.drawImage(layerImage, 0, 0, GraphicsPanel.PANELSIZE[0], GraphicsPanel.PANELSIZE[1],canvasPosition.x,canvasPosition.y,
						(int)(canvasPosition.x + GraphicsPanel.PANELSIZE[0]*GraphicsPanel.CurrentScale()), 
						(int)(canvasPosition.y + GraphicsPanel.PANELSIZE[1]*GraphicsPanel.CurrentScale()), GraphicsPanel.getInstance());
			}
		}
			
	}
	public boolean isActive(){
		return isActive;
	}
	public void setActive(boolean active){
		isActive = active;
		if (!activatedOnce)
			update(true);
		activatedOnce = true;
		GraphicsPanel.getInstance().repaint();
	}
	public void setData(T data){
		this.data = data;
		update(false);
	}
	public void setCanvasPosition(Point position){
		canvasPosition = position;
	}
	public String getName(){
		return layerName;
	}
	public BufferedImage getLayer(){
		return layerImage;
	}
	
}
